package com.szpx.mapper;

import com.szpx.entity.Consumer;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface ConsumerMapper {
    // 插入新的Consumer记录到数据库
    void insertConsumer(Consumer consumer);

    // 根据用户名查询Consumer，检查用户名是否已存在
    Consumer selectByUsername(String username);

    // 根据邮箱查询Consumer，检查邮箱是否已存在
    Consumer selectByEmail(String email);
    @Update("update consumer set password=#{password},name=#{name},sex=#{sex},image=#{image}," +
            "phone=#{phone},address=#{address},birthday=#{birthday},email=#{email} where username=#{username}")
    int update(Consumer consumer);

    /**
     * 根据手机号查询手机号
     * @param phone
     * @return
     */
    @Select("select * from consumer where phone=#{phone}")
    Consumer findByPhone(String phone);

    /**
     * 根据手机号修改密码
     * @param consumer
     * @return
     */
    @Update("update consumer set password=#{password} where phone=#{phone}")
    int updatePassword(Consumer consumer);


    /**
     * 修改手机号
     * @param consumer
     * @return
     */
    @Update("update consumer set phone=#{phone} where username=#{username}")
    int updatephone(Consumer consumer);

    /**
     * 根据邮箱 查询用户
     * @param email
     * @return
     */
    @Select("select * from consumer where email=#{email}")
    Consumer findByEmail(String email);
    /**
     * 修改邮箱
     * @param consumer
     * @return
     */
    @Update("update consumer set email=#{email} where username=#{username}")
    int updateemail(Consumer consumer);
    /**
     * 根据用户名修改修改密码
     * @param consumer
     * @return
     */
    @Update("update consumer set password=#{password} where username=#{username}")
    int updatePasswordByUsername(Consumer consumer);

}
